package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.AttendPunchDeptAddDTO;
import org.jsola.hr.dto.AttendPunchDeptUpdateDTO;
import org.jsola.hr.entity.AttendPunchDeptDO;
import org.jsola.hr.query.AttendPunchDeptQuery;
import org.jsola.hr.service.IAttendPunchDeptService;
import org.jsola.hr.vo.AttendPunchDeptVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPunchDeptTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPunchDeptService attendPunchDeptService;

    /**
     * 生成add测试数据
     * @return AttendPunchDeptAddDTO
     */
    public AttendPunchDeptAddDTO getAttendPunchDeptAddDTO(){
        AttendPunchDeptAddDTO attendPunchDeptAddDTO = new AttendPunchDeptAddDTO();
        attendPunchDeptAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendPunchDeptAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendPunchDeptAddDTO.setDeptId(getRandomValue("varchar",32));
        attendPunchDeptAddDTO.setDeptName(getRandomValue("varchar",100));
        attendPunchDeptAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        return attendPunchDeptAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPunchDeptUpdateDTO
     */
    public AttendPunchDeptUpdateDTO getAttendPunchDeptUpdateDTO(AttendPunchDeptVO attendPunchDeptVO){
        return attendPunchDeptService.selectDOById(attendPunchDeptVO.getId(), SITE_ID).to(AttendPunchDeptUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPunchDeptQuery
     */
    public AttendPunchDeptQuery getAttendPunchDeptQuery() {
        AttendPunchDeptQuery attendPunchDeptQuery = new AttendPunchDeptQuery();
        List<AttendPunchDeptDO> attendPunchDeptDOList = attendPunchDeptService.list(new AttendPunchDeptDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPunchDeptDOList)) {
            AttendPunchDeptDO attendPunchDeptDO = attendPunchDeptDOList.get(0);
            attendPunchDeptQuery = attendPunchDeptDO.to(AttendPunchDeptQuery.class);
            if (attendPunchDeptDO.getGmtCreate() != null) {
                attendPunchDeptQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPunchDeptDO.getGmtCreate(),-1));
                attendPunchDeptQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPunchDeptDO.getGmtCreate(),1));
            }
            if (attendPunchDeptDO.getGmtModified() != null) {
                attendPunchDeptQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPunchDeptDO.getGmtModified(),-1));
                attendPunchDeptQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPunchDeptDO.getGmtModified(),1));
            }
        }
        return attendPunchDeptQuery;
    }

    /**
     * 保存示例
     * @return AttendPunchDeptVO
     */
    public AttendPunchDeptVO saveAttendPunchDeptExample(){
        AttendPunchDeptAddDTO addDTO = this.getAttendPunchDeptAddDTO();
        AttendPunchDeptVO attendPunchDeptVO = attendPunchDeptService.save(addDTO,buildTokenUser());
        return attendPunchDeptVO;
    }


}

